/*
 *   AS IS License
 * ==Naive Coders==
 */
package org.naive.metawatch.converter.cap;

import java.text.ParseException;
import org.naive.metawatch.converter.parser.FieldSize;
import org.naive.metawatch.converter.parser.Parsed;
import org.naive.metawatch.converter.parser.ParsedInt;
import org.naive.metawatch.converter.parser.cap.CapParseContext;

/**
 *
 * @author gbu.000
 */
public class CapHeaderComponent extends CapComponent {

    @ParsedInt(FieldSize.INT)
    public int magic;
    @ParsedInt(FieldSize.BYTE)
    public byte minor_version;
    @ParsedInt(FieldSize.BYTE)
    public byte major_version;
    @ParsedInt(FieldSize.BYTE)
    public byte flags;
    @Parsed(CapPackageInfo.class)
    public CapPackageInfo package_info;
    
//    @ParsedIntArray(indexSize = FieldSize.BYTE, itemSize = FieldSize.BYTE)
//    public byte[] package_name;

    public boolean usesInts() {
        return (flags & 0x01) != 0;
    }

    public boolean hasExports() {
        return (flags & 0x02) != 0;
    }

    public boolean hasApplets() {
        return (flags & 0x04) != 0;
    }

    @Override
    public void parse(CapParseContext px) throws ParseException {
        super.parse(px);
        if(minor_version != 1 || major_version != 2) {
            throw new ParseException("Only 2.1 versions supported", px.getOffset());
        }
    }
    
}
